//
//  SearchResultModel.m
//  quxiangtao
//
//  Created by xbmios on 2018/10/9.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "SearchResultModel.h"

@implementation SearchResultModel

+ (void)searchResultModelWithPage:(NSInteger)page andType:(NSInteger)type searchText:(NSString *)searchStr sort_Id:(NSString *)sort_Id successBlock:(HttpRequestSuccess)successBlock failBlock:(HttpRequestFailed)failBlock {
    
    NSString *str = [NSString stringWithFormat:@"{\"type\" : \"%@\", \"device_value\" : \"%@\", \"device_type\" : \"%@\", \"pageno\" : \"%@\", \"pagesize\" : \"%@\", \"key\" : \"%@\", \"sort_id\" : \"%@\"}", [RSA encryptString:[NSString stringWithFormat:@"%zd", type] publicKey:PublicKey], [RSA encryptString:[DLayout identifier] publicKey:PublicKey], [RSA encryptString:@"UTDID" publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%zd", page] publicKey:PublicKey], [RSA encryptString:@"10" publicKey:PublicKey], [RSA encryptString:searchStr publicKey:PublicKey], [RSA encryptString:sort_Id publicKey:PublicKey]];
    
    [PPNetworkHelper POST:@"search/Index/searchList" parameters:@{@"json" : str} success:^(id responseObject) {
        
        NSLog(@"搜索结果数据%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] == 1) {
            
            NSDictionary *dict = responseObject[@"data"];
            NSDictionary *dict1 = dict[@"result_list"];
            
//            NSArray *array = dict1[@"map_data"];
            
            NSArray *array = nil;
            NSMutableDictionary *d = nil;
            if ([dict.allKeys containsObject:@"result_list"]) {
                
                array = [NSArray arrayWithArray:dict1[@"map_data"]];
                d = [NSMutableDictionary dictionaryWithDictionary:dict1];
            }else {
                
                array = [NSArray arrayWithArray:dict[@"map_data"]];
                d = [NSMutableDictionary dictionaryWithDictionary:dict];
            }
//            NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:dict1];
            
            if (array.count > 0) {
                
                NSArray *modelArr = [SearchResultModel mj_objectArrayWithKeyValuesArray:array];
                
                [d removeObjectForKey:@"map_data"];
                [d setObject:modelArr forKey:@"map_data"];
                
            }
            
            if (successBlock) {
                
                successBlock(d);
            }
        
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
        }
        
        
    } failure:^(NSError *error) {
        
        if (failBlock) {
            
            failBlock(error);
        }
        
        
    }];
    
}

@end
